﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using Krilib;
using System.Drawing;

namespace Wassrile.Config
{
    public class Config
    {
        [XmlIgnore()]
        public bool FirstBoot { get; private set; }

        public static Config Restore()
        {
            string target = Path.Combine(Bridge.Config.PluginPath, Define.ConfigFile);
            Config cog = null;
            if (File.Exists(target))
            {
                try
                {
                    cog = Bridge.CommonOperation.XMLLoad<Config>(target);
                    cog.FirstBoot = false;
                    return cog;
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show(
                        "Configuration load failed." + Environment.NewLine + e.ToString(),
                        "Wassrile Wassr Plugin",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Hand);
                }
            }
            cog = new Config();
            cog.FirstBoot = true;
            return cog;
        }

        public void Save()
        {
            string target = Path.Combine(Bridge.Config.PluginPath, Define.ConfigFile);
            Bridge.CommonOperation.XMLSave<Config>(this, target);
        }

        public Account account = new Account();

        public _Receive Receive = new _Receive();
        public class _Receive
        {
            public uint recvInterval = 30;
            public uint getHistoryNum = 3;
            public uint replyCheckInterval = 300;
            public bool traceFav = true;
        }

        public _Post Post = new _Post();
        public class _Post
        {
            public bool useSignature = false;
            public string Signature = "-Kr-";

            public bool refreshAfterPost = false;

            public bool alwaysReplyUseAt = false;

            public bool replyToFav = false;

            public bool dontReplyBehaviorInChannel = false;
        }

        public _Behavior Behavior = new _Behavior();
        public class _Behavior
        {
            public _PictPallet PictPallet = new _PictPallet();
            public class _PictPallet
            {
                public bool closeOnLostFocus = false;

                public bool saveSize = true;

                public bool saveLocation = false;

                public string[] customPalletItems = null;
            }
        }

        public _Detail Detail = new _Detail();
        public class _Detail
        {
            public bool pictgramBgWhiten = false;

            public bool overrideVia = false;

            public string overrideViaText = String.Empty;

            public bool extractGyazo = true;

            public bool pPalletNoBuffering = false;

            public _BootReceives BootReceives = new _BootReceives();
            public class _BootReceives
            {
                public bool friendTL = true;
                public uint friendTLPageNum = 3;
                public bool replyTL = true;
                public uint replyTLPageNum = 1;
                public bool myTL = true;
                public bool channelFeed = false;
            }

            public _Extra Extra = new _Extra();
            public class _Extra
            {
                public uint PublicTimelineRecvIdx = 1;


            }
        }

        [XmlIgnore()]
        public _State State = new _State();
        public class _State
        {
            public bool ImplyGlobalTL = false;

            public Point PalletLoc = new Point(300, 300);

            public Size PalletSize = new Size(300, 300);
        }
    }
}
